/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.dao.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import com.eelpo.common.util.BlankUtils;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * <pre>
 * 
 * 用户实体类，用于映射T_USER表(Persist Object)
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
@Entity
@Cacheable
@Table(name = "T_USER")
public class TUser implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 7546347129654518588L;

	/**
	 * 用户id
	 */
	@NotEmpty
	private String id;

	/**
	 * 用户名称
	 */
	@NotEmpty
	private String name;

	/**
	 * 用户帐号
	 */
	@NotEmpty
	private String account;

	/**
	 * 用户密码
	 */
	@NotEmpty
	private String password;

	/**
	 * 手机
	 */
	@NotEmpty
	private String mobile;

	/**
	 * 用户状态
	 */
	@NotNull
	private Byte status;

	/**
	 * 是否允许web登录
	 */
	@NotNull
	private Boolean allowWebLogin;

	/**
	 * 启用允许接口调用
	 */
	@NotNull
	private Boolean allowInterface;

	/**
	 * web鉴权模式
	 */
	@NotNull
	private Byte webAuthMode;

	/**
	 * 接口鉴权模式
	 */
	@NotNull
	private Byte interfaceAuthMode;

	/**
	 * 是否超级管理员
	 */
	@NotNull
	private Boolean superManager;

	/**
	 * 最后修改时间
	 */
	@NotNull
	private Date lastModifiedTime;

	/**
	 * 最后修改密码时间
	 */
	@NotNull
	private Date lastPasswordTime;

	/**
	 * 描述信息
	 */
	private String description;

	public TUser() {

	}

	public TUser(String id) {
		this.id = id;
	}

	@Id
	@Column(length = 36)
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@GeneratedValue(generator = "uuid")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(nullable = false, length = 64)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(nullable = false, unique = true, length = 32)
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	@Column(name = "passwd", nullable = false, length = 128)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(nullable = false, length = 32)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(nullable = false)
	public Byte getStatus() {
		return status;
	}

	public void setStatus(Byte status) {
		this.status = status;
	}

	@Column(nullable = false)
	public Boolean getAllowWebLogin() {
		return allowWebLogin;
	}

	public void setAllowWebLogin(Boolean allowWebLogin) {
		this.allowWebLogin = allowWebLogin;
	}

	@Column(nullable = false)
	public Boolean getAllowInterface() {
		return allowInterface;
	}

	public void setAllowInterface(Boolean allowInterface) {
		this.allowInterface = allowInterface;
	}

	@Column(nullable = false)
	public Byte getWebAuthMode() {
		return webAuthMode;
	}

	public void setWebAuthMode(Byte webAuthMode) {
		this.webAuthMode = webAuthMode;
	}

	@Column(nullable = false)
	public Byte getInterfaceAuthMode() {
		return interfaceAuthMode;
	}

	public void setInterfaceAuthMode(Byte interfaceAuthMode) {
		this.interfaceAuthMode = interfaceAuthMode;
	}

	@Column(nullable = false)
	public Boolean getSuperManager() {
		return superManager;
	}

	public void setSuperManager(Boolean superManager) {
		this.superManager = superManager;
	}

	@Column(nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastModifiedTime() {
		return lastModifiedTime;
	}

	public void setLastModifiedTime(Date lastModifiedTime) {
		this.lastModifiedTime = lastModifiedTime;
	}

	@Column(nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastPasswordTime() {
		return lastPasswordTime;
	}

	public void setLastPasswordTime(Date lastPasswordTime) {
		this.lastPasswordTime = lastPasswordTime;
	}

	@Column
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public boolean equals(Object obj) {
		if (BlankUtils.isBlank(obj) || !(obj instanceof TUser))
			return false;

		if (this == obj)
			return true;

		TUser user = (TUser) obj;

		if (BlankUtils.isBlank(this.id) || BlankUtils.isBlank(user.getId())) {
			return false;
		}

		return this.id.equals(user.getId());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public String toString() {
		return "TUser[name=" + name + ",account=" + account + "]";
	}
}
